﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace miSuperEngine
{
    public class Actor3D
    {
        Vector3 position;
        Vector3 rotation;
        Vector3 speed;
        Vector3 acceleration;
        Model model;
        public bool isActive = true;
        int currentTime, maxTime;
        public Actor3D(Vector3 pos, Vector3 spe,Vector3 accel,Model mod)
        {
            /*currentTime = 0;
            maxTime = 10000;
            position = pos;
            speed=spe;
            acceleration = accel;
            model = mod;*/
            newActor3D(pos, spe, accel, mod);
        }
        public void newActor3D(Vector3 pos, Vector3 spe, Vector3 accel, Model mod)
        {
            currentTime = 0;
            maxTime = 10000;
            position = pos;
            speed = spe;
            acceleration = accel;
            model = mod;
            isActive = true;
        }
        public virtual void update(GameTime gt)
        {
            speed += acceleration;
            position += speed;
            currentTime += gt.ElapsedGameTime.Milliseconds;
            if (currentTime > maxTime)
            {
                isActive = false;
            }
        }
        public virtual void draw(Camera cam)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] *
                        Matrix.CreateFromYawPitchRoll(rotation.Y,rotation.X,rotation.Z)
                        * Matrix.CreateTranslation(position);
                    effect.View = cam.view;
                    effect.Projection = cam.projection;
                }
                mesh.Draw();
            }
        }
    }
}
